<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>库存信息管理页面</title>
<script type="text/javascript">

//通过产品名称搜索
function searchStock(){
	$("#dg").datagrid('load',{
		"stockID":$("#s_stockID").val(),
		"productID":$("#s_product").combobox("getValue"),
		"wareHouseID":$("#s_wareHouse").combobox("getValue")

	});
}
//刷新
function refresh() {
	$("#dg").datagrid("load", {//使用load方法
		data : "customerName"//传到后台的变量
	});
}
var url;

<!--新增库存信息-->
function openStockAddDialog(){
	$("#dlg").dialog("open").dialog("setTitle","添加库存信息");
	url="${pageContext.request.contextPath}/addstock.do";
}


function addStock(){
	$("#fm").form("submit",{
		url:url,
       onSubmit:function(){
			
			var id1=document.getElementById("id1").value;
			var id2=document.getElementById("id2").value;
			var id3=document.getElementById("id3").value;
			if(id1==null||id1=='')
				{
				$.messager.alert("系统提示","库存编号不能为空!!!");
				return false;
				}
			if(id2==null||id2=='')
			{
			$.messager.alert("系统提示","产品名称不能为空!!!");
			return false;
			}
			if(id1==null||id1=='')
			{
			$.messager.alert("系统提示","库存名称不能为空!!!");
			return false;
			}

			return $(this).form("validate");
		},
		success:function(result){
			var result=eval('('+result+')');
			if(result.success){
				$.messager.alert("系统提示","保存成功");
				resetValue();
				$("#dlg").dialog("close");
				$("#dg").datagrid("reload");
			}else{
				$.messager.alert("系统提示","保存失败");
				return;
			}
		}
	});
}
<!--删除库存信息-->
function deleteStock(){
	var selectedRows=$("#dg").datagrid('getSelections');
	if(selectedRows.length==0){
		$.messager.alert("系统提示","请选择要删除的数据！");
		return;
	}
	var strIds=[];
	for(var i=0;i<selectedRows.length;i++){
		//productID为属性
		strIds.push(selectedRows[i].stockID);
	}
	var ids=strIds.join(",");
	$.messager.confirm("系统提示","您确认要删除这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
		if(r){
			$.post("${pageContext.request.contextPath}/deletestock.do",{ids:ids},function(result){
				if(result.success){
					$.messager.alert("系统提示","数据已成功删除！");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","数据删除失败！");
				}
			},"json");
		}
	});
	
}
//重置
function reset(){
	$("#s_stockID").val("");
	$("#s_product").combobox("setValue","");
	$("#s_wareHouse").combobox("setValue","");
	

}
   
function resetValue(){
	$("#id1").val("");
	$("#id2").combobox("setValue","");
	$("#id3").combobox("setValue","");
	$("#time3").datebox("setValue","");	
	$("#number").val("");
	$("#price").val("");
	
}

function closeStockDialog(){
	$("#dlg").dialog("close");
	resetValue();
}

//格式化
function formatProduct(val,row) {
	
	if(row.product.productName){
        return val.productName;
    }
    return val;
} 
function formatWareHouse(val,row) {
	
	if(row.wareHouse.wareHouseName){
        return val.wareHouseName;
    }
    return val;
} 
 
</script>
</head>
<body style="margin:1px;">
          <!-- 查询库存库信息 -->
	<table id="dg" title="库存信息管理" class="easyui-datagrid"
	  pagination="true" rownumbers="true"  fit="true"
	    url="${pageContext.request.contextPath}/stocklist.do"  toolbar="#tb">
		 <thead data-options="frozen:true">
				<tr>
					<th field="cb" checkbox="true" align="center"></th>
			 		<th field="stockID" width="160" align="center">库存编号</th>
			 		<th field="product" width="116" align="center" formatter="formatProduct">产品名称</th> 
                 <th field="wareHouse" width="116" align="center" formatter="formatWareHouse">仓库名称</th>
			 		<th field="productPrice" width="160" align="center">入库产品单价</th>
			 		<th field="productNum" width="160" align="center">产品数量</th>
			 		<th field="productTime" width="160" align="center">生产日期</th>
			 		
			 		
				</tr>
			</thead>
	</table>
		
	<div id="tb">
		
			&nbsp;库存编号：&nbsp;<input type="text" id="s_stockID" size="20" onkeydown="if(event.keyCode==13) searchStock()"/>

		
	 		&nbsp;产品名称：&nbsp;<input class="easyui-combobox" id="s_product" name="productID" editable="false" data-options="panelHeight:'150',editable:false,valueField:'productID',textField:'productName',url:'${pageContext.request.contextPath}/findAllProduct.do'" onkeydown="if(event.keyCode==13) searchStock()"/>
	 		&nbsp;仓库名称：&nbsp;<input class="easyui-combobox" id="s_wareHouse" name="wareHouseID" editable="false" data-options="panelHeight:'150',editable:false,valueField:'wareHouseID',textField:'wareHouseName',url:'${pageContext.request.contextPath}/findAllStockWareHouse.do'" onkeydown="if(event.keyCode==13) searchStock()/">
			
	 						
          <a href="javascript:searchStock()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
          <a href="javascript:reset()" class="easyui-linkbutton" iconCls="icon-redo" plain="true">重置</a>
          <a id="refreshbtn"
				href="javascript:refresh()" class="easyui-linkbutton"
				iconCls="icon-reload" plain="true">刷新</a>	
			<div>
			<a href="javascript:openStockAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
			<a href="javascript:deleteStock()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
				<div>
		</div>
		</div>
	</div>
	
	<!-- 添加库存信息 -->
	<div id="dlg" class="easyui-dialog" style="width: 400px;height:350px;padding: 10px 20px"
	  closed="true" buttons="#dlg-buttons">
	 	<form id="fm" method="post">
	 		<table cellspacing="8px">
	 		<tr>
	 				<td>库存编号：</td>
	 				<td><input type="text" id="id1" name="StockID" class="easyui-validatebox" required="true"/>&nbsp;<font color="red" >*</font></td>			
	 			</tr>
	 			
	 			<tr>
	 				<td>产品名称：</td>
	 				<td>
	 				<input class="easyui-combobox" id="id2" name="productID" required="true" editable="false" data-options="panelHeight:'150',editable:false,valueField:'productID',textField:'productName',url:'${pageContext.request.contextPath}/findAllProduct.do'"/>&nbsp;<font color="red">*</font>
	 	
	 				</td>
	 				
	 				</tr>
	 				<tr>
	 				<td>仓库名称：</td>
	 				<td>
	 				    <input class="easyui-combobox" id="id3" name="wareHouseID" required="true" editable="false" data-options="panelHeight:'150',editable:false,valueField:'wareHouseID',textField:'wareHouseName',url:'${pageContext.request.contextPath}/findAllStockWareHouse.do'"/>&nbsp;<font color="red">*</font>
	 				</td>
	 				</tr>
	 				 
	 				<tr>
	 			
	 				<td>生产日期：</td>
	 				<td>
	 					<input class="easyui-datebox" id="time3" name="productTime" style="width:158px;">&nbsp;<font color="red">*</font>
	 				</td>
	 				
	 				</tr>
	 				<tr>
	 				
	 				<td>入库单价：</td>
	 				<td>
	 					<input type="text" id="price" name="productPrice" class="easyui-validatebox" />&nbsp;<font color="red">*</font>
	 				</td>
	 				</tr>
	 			<tr>
	 				<td>库存数量：</td>
	 				<td>
	 					<input type="text" id="number" name="productNum" class="easyui-validatebox" />&nbsp;<font color="red">*</font>
	 				</td>
	 				
	 				</tr>
	 			
	 			
	 		</table>
	 			
	 	</form>
	</div>
	<div id="dlg-buttons">
		<a href="javascript:addStock()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeStockDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
	

</body>
</html>
 